<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item
              label="用户类型">
              <a-select default-value=""
                        placeholder="请选择用户类型"
                        v-model="queryParam.userType"
                        :getPopupContainer="(target) => target.parentNode"
                        allowClear>
                <a-select-option value="1">企业员工</a-select-option>
                <a-select-option value="2">经销商员工</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item
              label="使用状态">
              <a-select default-value=""
                        placeholder="请选择使用状态"
                        v-model="queryParam.status"
                        :getPopupContainer="(target) => target.parentNode"
                        allowClear>
                <a-select-option value="009">启用</a-select-option>
                <a-select-option value="003">停用</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item
              label="开始时间">
              <a-date-picker format="YYYY-MM-DD" valueFormat="YYYY-MM-DD" v-model="queryParam.startTime" v-decorator="['startTime', {}]" />
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="结束时间">
              <a-date-picker format="YYYY-MM-DD" valueFormat="YYYY-MM-DD" v-model="queryParam.endTime" v-decorator="[ 'endTime',{}]"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="start" @click="startorstop('009')">启用</a-button>
      <a-button type="primary" icon="stop" @click="startorstop('003')">停用</a-button>
      <a-button tabindex="primary" icon="delete" @click="batchDel">删除</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <!--<a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <sfaPicFactory-modal ref="modalForm" @ok="modalFormOk"></sfaPicFactory-modal>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import SfaPicFactoryModal from './modules/SfaPicFactoryModal'
  import { PageListMixin } from '@/mixins/PageListMixin'
  import { getAction } from '@/api/manage'
  import ARow from 'ant-design-vue/es/grid/Row'
  import ARangePicker from 'ant-design-vue/es/date-picker/RangePicker'

  export default {
    name: 'SfaPicFactoryList',
    mixins: [PageListMixin],
    components: {
      ARangePicker,
      ARow,
      SfaPicFactoryModal
    },
    data () {
      return {
        description: '海报宣传',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '标题',
            align:"center",
            dataIndex: 'title'
          },
          // {
          //   title: '用户类型',
          //   align:"center",
          //   dataIndex: 'userType_dictText',
          //   // customRender: function(text) {
          //   //     if (text === '1') {
          //   //       return '企业主用户';
          //   //     } else {
          //   //       return '员工用户';
          //   //     }
          //   // }
          // },
          {
            title: '海报类型',
            align:"center",
            dataIndex: 'dataType'
          },
          {
            title: '资料类型',
            align:"center",
            dataIndex: 'materialType'
          },
          {
            title: '组织',
            align:"center",
            dataIndex: 'orgName'
          },
          {
            title: '用户',
            align:"center",
            dataIndex: 'appointorName'
          },
          {
            title: '开始时间',
            align:"center",
            dataIndex: 'startTime'
          },
          {
            title: '结束时间',
            align:"center",
            dataIndex: 'endTime'
          },

          {
            title: '内容',
            align:"center",
            dataIndex: 'remarks'
          },
          {
            title: '停用启用状态',
            align:"center",
            dataIndex: 'status',
            customRender: function (text) {
              if (text === '009') {
                return '启用';
              } else {
                return '停用';
              }
            }
          },
          {
            title: '是否删除',
            align:"center",
            dataIndex: 'deleteStatus',
            customRender: function (text) {
              if (text === '009') {
                return '否';
              } else {
                return '是';
              }
            }
          },
          {
            title: '创建人姓名',
            align:"center",
            dataIndex: 'createName'
          },
          {
            title: '创建时间',
            align:"center",
            dataIndex: 'createDate'
          },
          {
            title: '更新人姓名',
            align:"center",
            dataIndex: 'updateName'
          },
          {
            title: '更新时间',
            align:"center",
            dataIndex: 'updateDate'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: window._CONFIG['domianSfaURL']+ "/picfactory/findPageList",
          deleteBatch: window._CONFIG['domianSfaURL']+ "/picfactory/deleteBatch",
          startOrStopUrl: window._CONFIG['domianSfaURL']+ "/picfactory/status/startOrStop"
        }
      }
    },
    methods: {
      startorstop: function(status) {
        if (!this.url.startOrStopUrl) {
          this.$message.error("请设置url启用停用!")
          return;
        }
        if (this.selectedRowKeys.length != 1) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          var id = this.selectedRowKeys[0];
          var that = this;
          that.loading = true;
          getAction(this.url.startOrStopUrl, {id: id, status: status}).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.loadData();
            } else {
              that.$message.warning(res.message);
            }
            that.loading = false;
          });
        }
      }
    }
  }
</script>

<style scoped>
  @import '~@assets/less/common.less';
</style>